<style>
    .file-url-a{
        background-color: #1497f3;
        color: #ffffff;
        border-radius: 3px;
        size: 8px !important;
        padding: 2px;
    }
</style>
<div class="layuimini-container">
    <div class="layuimini-main">
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
        </script>

    </div>
</div>

<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '{:url("upload/index")}',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox"},
                {field: 'id', width: 80, title: 'ID'},
                {field: 'platform_text', minWidth: 80, title: '存储位置'},
                {
                    field: 'cover_images', minWidth: 100, title: '图片信息', templet: function (d) {
                        if (d.type == 1) {
                            return '<img onclick="previewImg(\''+d.url+'\');" style="max-width: 200px; max-height: 40px;" src="' + d.url + '">';
                        } else if (d.cover_images != '') {
                            return '<img onclick="previewImg(\''+d.cover_images+'\');" style="max-width: 200px; max-height: 40px;" src="' + d.cover_images + '">';
                        } else {
                            return '';
                        }
                    }
                },
                {
                    field: 'url', minWidth: 160, title: '保存地址', templet: function (d) {
                        return '<a class="file-url-a" target="_blank" href="' + d.url + '">' + d.url + '</a>';
                    }
                },
                {field: 'title', minWidth: 100, title: '文件原名'},
                {field: 'ext', minWidth: 80, title: '后缀'},
                {field: 'size_text', minWidth: 80, title: '文件大小'},
                {field: 'create_time', minWidth: 80, title: '创建时间'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            var event = obj.event;
            if (event === 'add') {  // 监听添加操作
                openDetail('新增', '{:url("upload/add")}');
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                var ids = [];
                for (var i = 0; i < data.length; i++) {
                    ids.push(data[i]['id']);
                }
                delItem('{:url("upload/del")}', ids);
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'delete') {
                delItem('{:url("upload/del")}', data.id);
            }
        });
    });
</script>

</body>
</html>